-
-
Notifications
You must be signed in to change notification settings - Fork 340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding new slash command /tools
to use LLMs with your own custom tools
#991
base: main
Are you sure you want to change the base?
Conversation
Enabling use of custom tools (functions) with LLMs
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like using an entrypoint approach would be more scalable than reading from user directory. The kernel may live on a different computer than the server so the server will often not have access to read from the mytools.py
that user created.
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
* adds wildcard matching to /learn * Add documentation * improve docs * cleanup * adds wildcard matching to /learn * Add documentation * improve docs * Update docs/source/users/index.md Co-authored-by: Michał Krassowski <[email protected]> * update for test * improve test * improve directory handling * remove dir only logic --------- Co-authored-by: Michał Krassowski <[email protected]>
* Add openrouter.ai support * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
for more information, see https://pre-commit.ci
@dlqqq Updated this PR to include:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@srdas Thank you for working on this! I've left some points of feedback below. No rush on addressing this, since we're still using this PR to experiment & test.
High-level callouts (subject to future edits):
- (low priority) Can you add typing to the methods & attributes in
tools.py
? The lack of typing is causing the typing tests (done viamypy
) to fail in CI.
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
@dlqqq Note: While the PR is working for Bedrock Chat models, it needs to be tested for other providers. Additional classes may need to be added to each partner provider module or new modules may be needed. I will work on this next.
|
for more information, see https://pre-commit.ci
This draft PR proposes a new feature enabling the use of custom tools (functions) with LLMs. Lots of work to do here and see the end of this note for all the design decisions to make.
In many situations LLMs will handle complex mathematical formulas quite well and return correct answers, but this is often not the case. Even for textual repsonses, using custom functions can constrain responses to formats and content that is more accurate and acceptable.
This PR adds a new a slash command
/tools
that directs the LLM to use functions from a tools library that you provide. This is a single file titledmytools.py
which may be stored in the default directory, that is, the one from which Jupyter is started. We provide an example of the tools file here, containing just three functions. Make sure to add the@tool
decorator to each function and to import all packages that are not already installed within each function. The functions below are common financial formulas that are widely in use and you may expect that an LLM would be trained on these. While this is accurate, we will see that the LLM is unable to accurately execute the math in these formulas.Each function contains the
@tool
decorator and the required imports. Note also the comment string that describes what each tool does. This will help direct the LLM to relevant tool. Providing sufficient guiding comments in the function is helpful in the form of comment strings, variable annotations, and expolicit argument comments, example of which are shown in the code above. For example, default values in comments will be used by the LLM if the user forgets to provide them (for example, see the explicit mention of a 6% interest rate incalculate_monthly_payment
function above).When the
/tools
command is used, Jupyter AI will bind the custom tools file to the LLM currently in use and build aLangGraph
(https://langchain-ai.github.io/langgraph/). It will use this graph to respond to the query and use the appropriate tools, if available. In the examples below, we use Claude Haiku as the base model:As an example, submit this query in the chat interface without using tools: "What is the price of a put option where the stock price is 100, the exercise price is 101, the time to maturity is 1 year, the risk free rate is 3%, the dividend rate is zero, and the stock volatility is 20%?" The correct answer to this query is $6.93. However, though the LLM returns the correct formula, it computes the answer incorrectly:
Next, use the
/tools
command with the same query to get the correct answer:While this is the simplest implementation and the first use of
LangGraph
in Jupyter AI, there are several improvements and additions to consider:/tools
Make the location of theDONEmytools.py
file flexible, or pass it as a parameter in the slash command?Pass tools file location on startup, or in chat? Only allow one tools file, or handle multiple tool files.DONEMake handling the different providers (Chat*) and models (model_id) part of the UI?RemovedImprove error handlingDONEDocumentation. Currently this is sufficient for users, but maybe add documentation for developers to use LangGraph in a more extended manner. Long term: Using the more advanced features of LangGraph, Agents, Multi-agentic workflows, etc.DONE